/**
 * 
 */
package org.dragonfire.irc.server;

import java.net.Socket;
import java.util.HashMap;

/**
 * @author Darth Android
 * @date Oct 27, 2007
 */
public class ServerConnection implements Comparable<ServerConnection> {

	private String name;

	private HashMap<String, Integer> linkedServers = new HashMap<String, Integer>();

	private Socket connection;

	public ServerConnection(Socket sock) {
		connection = sock;
	}

	public int getServerDistance(String name) {
		if (linkedServers.get(name) != null)
			return linkedServers.get(name);
		return -1;
	}

	public boolean equals(Object other) {
		if (other instanceof ServerConnection) {
			return ((ServerConnection) other).name.equalsIgnoreCase(name);
		}
		return false;
	}

	public String[] getServerLinks() {
		return linkedServers.keySet().toArray(new String[linkedServers.size()]);
	}

	public boolean isActive() {
		return connection != null;
	}

	public int compareTo(ServerConnection o) {
		return name.compareToIgnoreCase(o.name);
	}

}
